package com.tgy.基础学习.Thread.Normal;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 送你一块二向箔
 * @date 2021/11/08 11:03
 */
/*
线程睡眠状态
模拟网络延时，模拟倒计时
每个对象都有一把锁，sleep不会释放锁
 */

public class ThreadSleep {
    public void tenDown() throws InterruptedException {
        int num = 10 ;
        while (true){
            Thread.sleep(1000);
            System.out.println(num--);
            if (num == 0){
                break;
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        ThreadSleep thread = new ThreadSleep();
        thread.tenDown();

        Date startTime = new Date(System.currentTimeMillis());
        while (true){
            Thread.sleep(1000);
            System.out.println(new SimpleDateFormat("HH:mm:ss").format(startTime));
            startTime = new Date(System.currentTimeMillis());
        }
    }
}
